package com.tjetc.service.impl;

import com.tjetc.entity.Shoesizes;
import com.tjetc.dao.ShoesizesDao;
import com.tjetc.service.ShoesizesService;
import com.tjetc.util.Pager;
import com.tjetc.util.vo.ShoesizesParam;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 尺寸表(Shoesizes)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:06:07
 */
@Service("shoesizesService")
public class ShoesizesServiceImpl implements ShoesizesService {
    @Resource
    private ShoesizesDao shoesizesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param ssid 主键
     * @return 实例对象
     */
    @Override
    public Shoesizes queryById(Long ssid) {
        return this.shoesizesDao.queryById(ssid);
    }

    /**
     * 分页查询
     *
     * @param shoesizes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Object queryCountByPage(ShoesizesParam shoesizesParam) {
        //查询总记录数
        Integer recordCount = shoesizesDao.count(shoesizesParam.getSname(),shoesizesParam.getSize(),shoesizesParam.getSex());
        //构建分页信息对象
        Pager pager = new Pager(shoesizesParam.getPageNum(),shoesizesParam.getPageSize(), recordCount);
        //根据pager查询需要的数据
        List<Shoesizes> list = shoesizesDao.queryAll(shoesizesParam.getSname(),shoesizesParam.getSize(),shoesizesParam.getSex(),pager.getStart(), shoesizesParam.getPageSize());
        //将分页信息和查询到的数据一起返回到前端
        HashMap<String,Object> map = new HashMap<>();
        map.put("pager",pager);
        map.put("list",list);
        return map;
    }

    /**
     * 新增数据
     *
     * @param shoesizes 实例对象
     * @return 实例对象
     */
    @Override
    public Shoesizes insert(Shoesizes shoesizes) {
        this.shoesizesDao.insert(shoesizes);
        return shoesizes;
    }

    /**
     * 修改数据
     *
     * @param shoesizes 实例对象
     * @return 实例对象
     */
    @Override
    public Shoesizes update(Shoesizes shoesizes) {
        this.shoesizesDao.update(shoesizes);
        return this.queryById(shoesizes.getSsid());
    }

    /**
     * 通过主键删除数据
     *
     * @param ssid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long ssid) {
        return this.shoesizesDao.deleteById(ssid) > 0;
    }
}
